package cn.com.shopec.erp.stock.excel.impl;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import cn.com.shopec.erp.common.excel.ExcelBaseExport;
import cn.com.shopec.erp.common.utils.DateUtil;
import cn.com.shopec.erp.financing.entity.SupplierSettlement;

public class SupplierSettlementExcelExport extends ExcelBaseExport {

	public SupplierSettlementExcelExport(List<SupplierSettlement> data, String fileName,
			HttpServletResponse response) {
		super(data, fileName, response);
	}

	@Override
	protected Row setColumnMapping(Object data, Row row) {
		SupplierSettlement supplierSettlement = (SupplierSettlement) data;
		int cellIndex = 0;
		Cell cell = row.createCell(cellIndex++);
		cell.setCellValue(supplierSettlement.getSettlementNo());

		cell = row.createCell(cellIndex++);
		cell.setCellValue(supplierSettlement.getSupplierName());

		cell = row.createCell(cellIndex++);
		DecimalFormat df = new DecimalFormat("######0.00"); 
		cell.setCellValue(df.format(supplierSettlement.getSettlementTotal()));

		cell = row.createCell(cellIndex++);
		cell.setCellValue(DateUtil.formatDefaultDate(supplierSettlement.getStartDate()));

		cell = row.createCell(cellIndex++);
		cell.setCellValue(DateUtil.formatDefaultDate(supplierSettlement.getEndDate()));

		cell = row.createCell(cellIndex++);
		cell.setCellValue(DateUtil.formatTimesTampDate(supplierSettlement.getSettlementTime()));
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(getCheckState(supplierSettlement.getCheckState()));
		
		cell = row.createCell(cellIndex++);
		cell.setCellValue(DateUtil.formatTimesTampDate(supplierSettlement.getCheckTime()));
		
		return row;
	}

	@Override
	protected List<String> setExcelTitleValue() {
		List<String> title = new ArrayList<String>();
		title.add("结算编号");
		title.add("供应商名称");
		title.add("结算总金额(元)");
		title.add("结算开始日期");
		title.add("结算结束日期");
		title.add("结算时间");
		title.add("审核状态");
		title.add("审核时间");
		return title;
	}

	private String getCheckState(int state){
		String stateName = "";
		switch(state){
			case 0 : stateName = "未审核";break;
			case 1 : stateName = "已审核";break;
			case 2 : stateName = "审核不通过";break;
			default: break;
		}
		return stateName;
	}
}
